

** 26.2.2025

** Merger syntax

** Project: Making time to be informed

**********************************************************************************

/* Destination folder where original datasets are deposited */
cd "C:\Users\irene.svitores\OneDrive - Universidad Rey Juan Carlos\1_Research\2020 Media project\JOP - Replication materials\3. LISS pooled\1. Original Data"

********************************************************************************

**# 1. Clean and prepare the datasets with questions regarding politics.

** 2007 dataset 
use "cv08a_1.1p_EN.dta", clear
rename cv08a* po*
g file="cv08a"
g wave=2007
/* drop variables not used */ drop po057 po059 po060 po061 po062 po063 po064 po155 po156 po157 po158 po159 po076 po077 po078 po079 po080 po081 po082 po083 po084 po085 po086 po087 po088 po089 po090 po091 po092 po093 po094 po095 po096 po097
save "wavepol1.dta"


** 2008 dataset 
use "cv09b_2.1p_EN.dta", clear
rename cv09b* po*
ta po_m
g wave=2008
g file="cv09b"
/* drop variables not used */ drop po057 po059 po060 po061 po062 po063 po064 po155 po156 po157 po158 po159 po076 po077 po078 po079 po080 po081 po082 po083 po084 po085 po086 po087 po088 po089 po090 po091 po092 po093 po094 po095 po096 po097
save "wavepol2.dta"


** 2009 dataset -
use "cv10c_EN_1.0p.dta", clear
rename cv10c* po*
ta po_m
g wave=2009
g file= "cv10c"
/* drop variables not used */ drop po057 po059 po060 po061 po062 po063 po064 po155 po156 po157 po158 po159 po076 po077 po078 po079 po080 po081 po082 po083 po084 po085 po086 po087 po088 po089 po090 po091 po092 po093 po094 po095 po096 po097
save "wavepol3.dta"


** 2010 dataset
use "cv11d_EN_1.0p.dta", clear
rename cv11d* po*
ta po_m
g wave=2010
g file = "cv11d"
/* drop variables not used */ drop po173 po174 po175 po176 po177 po178 po179 po180 po181 po182 po183 po184 po185 po186 po187 po188 po189 po190 po191 po192 po155 po156 po157 po158 po159
save "wavepol4.dta"


** 2011 dataset
use "cv12e_EN_1.0p.dta", clear
rename cv12e* po*
ta po_m
g wave=2011
g file = "cv12e"
/* drop variables not used */ drop po173 po174 po175 po176 po177 po178 po179 po180 po181 po182 po183 po184 po185 po186 po187 po188 po197 po198 po191 po192 po155 po156 po157 po158 po159
destring po161 po162 po163 po164, replace /* Some of the variables change metrics, destring required */ 
save "wavepol5.dta"


** 2012 dataset
use "cv13f_EN_1.0p.dta", clear
rename cv13f* po*
ta po_m
g wave=2012
g file = "cv13f"
/* drop variables not used */ drop po211 po212 po213 po214 po215 po216 po217 po218 po219 po220 po221 po222 po223 po224 po225 po226 po227 po228 po229 po230 po231 po232 po155 po156 po157 po158 po159
/* some variables changed metrics, destring permits the merger to work*/ destring po161 po162 po163 po164, replace
save "wavepol6.dta"


** 2013 dataset 
use "cv14g_EN_1.0p.dta", clear
rename cv14g* po*
ta po_m
g wave=2013
g file = "cv14g"
/* drop variables not used */ drop po211 po212 po213 po214 po215 po216 po217 po218 po219 po220 po221 po222 po223 po224 po225 po226 po227 po228 po229 po230 po231 po239 po155 po156 po157 po158 po159
/* glitch solving for the merger */ destring po161 po162 po163 po164, replace
save "wavepol7.dta"


** 2015 dataset
use "cv16h_EN_1.0p.dta", clear
rename cv16h* po*
/* Variable po_m is not available in this wave because there was some experimentation with the administering of the questionnaire at this point. The variable is construed out of other existing variables in the dataset regarding when the fieldwork was conducted.*/
ta maandnr
g po_m=maandnr
replace po_m = maandnr_lang if po_m >= . 
replace po_m = maandnr_deel1 if po_m >=.
replace po_m = maandnr_deel2 if po_m >=.
replace po_m = maandnr_deel3 if po_m >=.
replace po_m = maandnr_a if po_m >=.
replace po_m = maandnr_b if po_m >=.
ta po_m
g wave=2015
g file = "cv16h"
/* drop variables not used */ drop po211 po212 po213 po214 po215 po216 po217 po218 po219 po220 po221 po222 po223 po224 po225 po226 po227 po228 po240 po230 po231 po241 po155 po156 po157 po158 po159
save "wavepol8.dta"


** 2016 dataset
use "cv17i_EN_1.0p.dta", clear
rename cv17i* po*
ta po_m
g wave=2016
g file = "cv17i"
/* drop variables not used */ drop po211 po212 po213 po214 po215 po216 po217 po218 po219 po220 po221 po264 po265 po222 po266 po224 po225 po226 po227 po267 po240 po230 po231 po241 po268 po269 po155 po156 po157 po158 po159
save "wavepol9.dta"


** 2017 dataset
use "cv18j_EN_1.0p.dta", clear
rename cv18j* po*
ta po_m1
g po_m=po_m1
g wave=2017
g file = "cv18j"
/* drop variables not used */ drop po211 po213 po215 po216 po218 po214 po212 po217 po220 po221 po219 po264 po305 po222 po224 po226 po227 po240 po225 po266 po267 po231 po241 po230 po268 po306 po274 po275 po276 po277 po278 po279 po280 po281 po282 po283
save "wavepol10.dta"


** 2018 dataset
use "cv19k_EN_1.0p.dta", clear
rename cv19k* po*
ta po_m1
g po_m=po_m1
g wave=2018
g file = "cv19k"
/* drop variables not used */ drop po211 po213 po215 po216 po218 po214 po212 po217 po220 po221 po219 po264 po305 po222 po224 po226 po240 po225 po266 po267 po231 po241 po230  po306 po274 po275 po276 po277 po278 po279 po280 po281 po282 po283
save "wavepol11.dta"


** 2019 dataset
use "cv20l_EN_1.0p.dta", clear
rename cv20l* po*
ta po_m1
g wave=2019
g file = "cv20l"
g po_m=po_m1
/* drop variables not used */ drop po211 po213 po215 po216 po218 po214 po212 po217 po220 po221 po219 po264 po305 po222 po224 po240 po225 po266 po267 po241 po230 po306 po274 po275 po276 po277 po278 po279 po280 po281 po282 po283
save "wavepol12.dta"


** 2020 dataset
use "cv21m_EN_1.0p.dta", clear
rename cv21m* po*
ta po_m1
g po_m=po_m1
g wave=2020
g file= "cv21m"
/* drop variables not used */ drop po211 po213 po215 po216 po218 po214 po212 po217 po220 po221 po219 po264 po305 po222 po224 po240 po225 po266 po267 po230 po306 po274 po275 po276 po277 po278 po279 po280 po281 po282 po283
save "wavepol13.dta"


**2021 dataset
use "cv22n_EN_1.0p.dta", clear
rename cv22n* po*
ta po_m1
g po_m=po_m1
g wave=2021
g file = "cv22n"
/* drop variables not used */ drop po211 po213 po215 po216 po218 po214 po212 po217 po220 po221 po219 po264 po305 po222 po224 po240 po225 po267 po230 po306 po274 po275 po276 po277 po278 po279 po280 po281 po282 po283
save "wavepol14.dta"


** 2022 dataset
use "cv23o_EN_1.0p.dta", clear
rename cv23o* po*
ta po_m1
g po_m=po_m1
g wave=2022
g file = "cv23o"
/* drop variables not used */ drop po211 po213 po215 po216 po218 po214 po212 po217 po220 po221 po219 po264 po305 po222 po224 po240 po225 po230 po306 po274 po275 po276 po277 po278 po279 po280 po281 po282 po283
save "wavepol15.dta"


********************************************************************************

** Merger of the family datasets

/* Combine the waves into a single dataset */ 
use "wavepol1.dta", clear
append using "wavepol2.dta"
append using "wavepol3.dta"
append using "wavepol4.dta"
append using "wavepol5.dta", force
append using "wavepol6.dta", force
append using "wavepol7.dta", force
append using "wavepol8.dta"
append using "wavepol9.dta"
append using "wavepol10.dta"
append using "wavepol11.dta"
append using "wavepol12.dta"
append using "wavepol13.dta"
append using "wavepol14.dta"
append using "wavepol15.dta"

/* Save the new dataset*/
save "politics1-15.dta"

/* drop variables*/
drop po106 po107 po108 po270 po313 po312 po314 po315 po316 po317 po318 po319 po320 po325 po326 po327 po328 po329 po331 po332 po330 po333 po334
save "politics1-15.dta", replace



********************************************************************************
********************************************************************************

**# 2. Clean and prepare the datasets with questions regarding family composition.

** 2008 dataset
use "cf08a_2p_EN.dta", clear 
/* Rename of variables for merger */ rename cf08* f*
/* Generate wave and file variables */ g wave=2008
g file = "cf08a"
/* Drop variables not needed to alleviate dataset */ drop fa005 fa006 fa007 fa008 fa009 fa010 fa011 fa012 fa013 fa014 fa015 fa016 fa017 fa398 fa018 fa399 fa019 fa400 fa020 fa021 fa022 fa023 fa053 fa054 fa055 fa056 fa057 fa058 fa059 fa060 fa061 fa062 fa063 fa064 fa065 fa066 fa067 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa167 fa168 fa169 fa170 fa171 fa172 fa173 fa174 fa175 fa176 fa177 fa178 fa179 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa225 fa226 fa227 fa228 fa229 fa230 fa231 fa232 fa233 fa234 fa235 fa236 fa237 fa267 fa268 fa269 fa270 fa271 fa272 fa273 fa274 fa275 fa276 fa277 fa278 fa279 fa280 fa281 fa282 fa283 fa284 fa285 fa286 fa287 fa288 fa289 fa290 fa291 fa292 fa293 fa294 fa295 fa296 fa297 fa298 fa299 fa300 fa301 fa302 fa303 fa304 fa305 fa306 fa307 fa308 fa309 fa310 fa311 fa312 fa313 fa314 fa315 fa316 fa317 fa318 fa319 fa320 fa321 fa322 fa323 fa324 fa325 fa326 fa355 fa356 fa357 fa358 fa359 fa360 fa361 fa362 fa363 fa364 fa365 fa366 fa367 fa368 fa369 fa370 fa371 fa388 fa389 fa390 fa391 fa392
/* Save dataset */ save "wavefam1.dta", replace
								
** 2009 dataset									
use "cf09b_EN_2.2p.dta", clear
rename cf09b* fa*
g wave=2009
g file = "cf09b"
drop fa005 fa006 fa007 fa008 fa009 fa010 fa011 fa012 fa013 fa014 fa015 fa016 fa017 fa398 fa018 fa399 fa019 fa400 fa020 fa021 fa022 fa023 fa053 fa054 fa055 fa056 fa057 fa058 fa059 fa060 fa061 fa062 fa063 fa064 fa065 fa066 fa067 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166
drop fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa225 fa226 fa227 fa228 fa229 fa230 fa231 fa232 fa233 fa234 fa235 fa236 fa237 fa267 fa268 fa269 fa270 fa271 fa272 fa273 fa274 fa275 fa276 fa277 fa278 fa279 fa280 fa281 fa282 fa283 fa284 fa285 fa286 fa287 fa288 fa289 fa290 fa291 fa292 fa293 fa294 fa295 fa296 fa297 fa298 fa299 fa300 fa301 fa302 fa303 fa304 fa305 fa306 fa307 fa308 fa309 fa310 fa311 fa312 fa313 fa314 fa315 fa316 fa317 fa318 fa319 fa320 fa321 fa322 fa323 fa324 fa325 fa326 fa355 fa356 fa357 fa358 fa359 fa360 fa361 fa362 fa363 fa364 fa365 fa366 fa367 fa368 fa369 fa370 fa371 fa388 fa389 fa390 fa391 fa392
save "wavefam2.dta"

** 2010 dataset
use "cf10c_EN_1.0p.dta", clear
rename cf10c* fa*
g wave=2010
drop fa005 fa006 fa007 fa008 fa009 fa010 fa011 fa012 fa013 fa014 fa015 fa016 fa017 fa398 fa018 fa399 fa019 fa400 fa020 fa021 fa022 fa023 fa053 fa054 fa055 fa056 fa057 fa058 fa059 fa060 fa061 fa062 fa063 fa064 fa065 fa066 fa067 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa225 fa226 fa227 fa228 fa229 fa230 fa231 fa232 fa233 fa234 fa235 fa236 fa237 fa267 fa268 fa269 fa270 fa271 fa272 fa273 fa274 fa275 fa276 fa277 fa278 fa279 fa280 fa281 fa282 fa283 fa284 fa285 fa286 fa287 fa288 fa289 fa290 fa291 fa292 fa293 fa294 fa295 fa296 fa297 fa298 fa299 fa300 fa301 fa302 fa303 fa304 fa305 fa306 fa307 fa308 fa309 fa310 fa311 fa312 fa313 fa314 fa315 fa316 fa317 fa318 fa319 fa320 fa321 fa322 fa323 fa324 fa325 fa326 fa355 fa356 fa357 fa358 fa359 fa360 fa361 fa362 fa363 fa364 fa365 fa366 fa367 fa368 fa369 fa370 fa371 fa388 fa389 fa390 fa391 fa392
save "wavefam3.dta"

** 2011 dataset
use "cf11d_EN_1.1p.dta", clear
rename cf11d* fa*
g wave=2011
drop fa005 fa006 fa007 fa008 fa009 fa010 fa011 fa012 fa013 fa014 fa015 fa016 fa017 fa398 fa018 fa399 fa019 fa400 fa020 fa021 fa022 fa023 fa053 fa054 fa055 fa056 fa057 fa058 fa059 fa060 fa061 fa062 fa063 fa064 fa065 fa066 fa067 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa225 fa226 fa227 fa228 fa229 fa230 fa231 fa232 fa233 fa234 fa235 fa236 fa237 fa267 fa268 fa269 fa270 fa271 fa272 fa273 fa274 fa275 fa276 fa277 fa278 fa279 fa280 fa281 
save "wavefam4.dta"

** 2012 dataset
use "cf12e_EN_2.1p.dta", clear
rename cf12e* fa*
g wave=2012
drop fa005 fa006 fa007 fa008 fa009 fa010 fa011 fa012 fa013 fa014 fa015 fa016 fa017 fa398 fa018 fa399 fa019 fa400 fa020 fa021 fa022 fa023 fa053 fa054 fa055 fa056 fa057 fa058 fa059 fa060 fa061 fa062 fa063 fa064 fa065 fa066 fa067 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa225 fa226 fa227 fa228 fa229 fa230 fa231 fa232 fa233 fa234 fa235 fa236 fa237 fa267 fa268 fa269 fa270 fa271 fa272 fa273 fa274 fa275 fa276 fa277 fa278 fa279 fa280 fa281 
save "wavefam5.dta"

** 2013 dataset
use "cf13f_EN_1.1p.dta", clear
rename cf13f* fa*
g wave=2013
drop fa005 fa006 fa007 fa008 fa009 fa010 fa011 fa012 fa013 fa014 fa015 fa016 fa017 fa398 fa018 fa399 fa019 fa400 fa020 fa021 fa022 fa023 fa053 fa054 fa055 fa056 fa057 fa058 fa059 fa060 fa061 fa062 fa063 fa064 fa065 fa066 fa067 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa225 fa226 fa227 fa228 fa229 fa230 fa231 fa232 fa233 fa234 fa235 fa236 fa237 fa267 fa268 fa269 fa270 fa271 fa272 fa273 fa274 fa275 fa276 fa277 fa278 fa279 fa280 fa281 
save "wavefam6.dta"

** 2014 dataset
use "cf14g_EN_1.1p.dta", clear
rename cf14g* fa*
g wave=2014
drop fa005 fa006 fa007 fa008 fa009 fa010 fa011 fa012 fa013 fa014 fa015 fa016 fa017 fa398 fa018 fa399 fa019 fa400 fa020 fa021 fa022 fa023 fa053 fa054 fa055 fa056 fa057 fa058 fa059 fa060 fa061 fa062 fa063 fa064 fa065 fa066 fa067 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa225 fa226 fa227 fa228 fa229 fa230 fa231 fa232 fa233 fa234 fa235 fa236 fa237 fa267 fa268 fa269 fa270 fa271 fa272 fa273 fa274 fa275 fa276 fa277 fa278 fa279 fa280 fa281 
save "wavefam7.dta"

** 2015 dataset
use "cf15h_EN_1.0p.dta", clear
rename cf15h* fa*
g wave=2015
** Changes in the variables in terms of order/names - add some questions (that are dropped about feelings regarding respondent's mother and children)
drop fa432 fa005 fa449 fa007 fa008 fa008 fa450 fa011 fa012 fa401 fa013 fa014 fa015 fa016 fa451 fa398 fa018 fa399 fa019 fa400 fa020 fa452 fa022 fa453 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa489 fa490 fa491 fa492 fa493 fa494 fa495 fa496 fa497 fa498 fa499 fa500 fa501 fa502 fa503 fa434 fa435 fa436 fa437 fa438 fa439 fa440 fa441 fa442 fa443 fa444 fa445 fa446 fa447 fa448 fa297 fa298 fa299 fa300 fa301 fa302 fa303 fa304 fa305 fa306 fa307 fa308 fa309 fa310 fa311 fa312 fa313 fa314 fa315 fa316 fa317 fa318 fa319 fa320 fa321 fa322 fa323 fa324 fa325 fa326 fa340 fa341 fa342 fa343 fa344 fa345 fa346 fa347 fa348 fa349 fa350 fa351 fa352 fa353 fa354 fa355 fa356 fa357 fa358 fa359 fa360 fa361 fa362 fa363 fa364 fa365 fa366 fa367 fa368 fa369 fa504 fa505 fa506 fa507 fa508 fa509 fa510 fa511 fa512 fa513 fa514 fa515 fa516 fa517 fa518 fa519 fa520 fa521 fa388 fa389 fa390 fa391 fa392 
save "wavefam8.dta"

** 2016 dataset
use "cf16i_EN_1.0p.dta", clear
rename cf16i* fa*
g wave=2016
** Changes in the variables in terms of order/names
drop fa432 fa005 fa449 fa007 fa008 fa008 fa450 fa011 fa012 fa401 fa013 fa014 fa015 fa016 fa451 fa398 fa018 fa399 fa019 fa400 fa020 fa452 fa022 fa453 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa489 fa490 fa491 fa492 fa493 fa494 fa495 fa496 fa497 fa498 fa499 fa500 fa501 fa502 fa503 fa434 fa435 fa436 fa437 fa438 fa439 fa440 fa441 fa442 fa443 fa444 fa445 fa446 fa447 fa448 fa297 fa298 fa299 fa300 fa301 fa302 fa303 fa304 fa305 fa306 fa307 fa308 fa309 fa310 fa311 fa312 fa313 fa314 fa315 fa316 fa317 fa318 fa319 fa320 fa321 fa322 fa323 fa324 fa325 fa326 fa340 fa341 fa342 fa343 fa344 fa345 fa346 fa347 fa348 fa349 fa350 fa351 fa352 fa353 fa354 fa355 fa356 fa357 fa358 fa359 fa360 fa361 fa362 fa363 fa364 fa365 fa366 fa367 fa368 fa369 fa504 fa505 fa506 fa507 fa508 fa509 fa510 fa511 fa512 fa513 fa514 fa515 fa516 fa517 fa518 fa519 fa520 fa521 fa388 fa389 fa390 fa391 fa392
save "wavefam9.dta"

** 2017 dataset
use "cf17j_EN_1.0p.dta", clear
rename cf17j* fa*
g wave=2017
** Changes in the variables in terms of order/names
drop fa432 fa005 fa449 fa007 fa008 fa008 fa450 fa011 fa012 fa401 fa013 fa014 fa015 fa016 fa451 fa398 fa018 fa399 fa019 fa400 fa020 fa452 fa022 fa453 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa489 fa490 fa491 fa492 fa493 fa494 fa495 fa496 fa497 fa498 fa499 fa500 fa501 fa502 fa503 fa434 fa435 fa436 fa437 fa438 fa439 fa440 fa441 fa442 fa443 fa444 fa445 fa446 fa447 fa448 fa297 fa298 fa299 fa300 fa301 fa302 fa303 fa304 fa305 fa306 fa307 fa308 fa309 fa310 fa311 fa312 fa313 fa314 fa315 fa316 fa317 fa318 fa319 fa320 fa321 fa322 fa323 fa324 fa325 fa326 fa340 fa341 fa342 fa343 fa344 fa345 fa346 fa347 fa348 fa349 fa350 fa351 fa352 fa353 fa354 fa355 fa356 fa357 fa358 fa359 fa360 fa361 fa362 fa363 fa364 fa365 fa366 fa367 fa368 fa369 fa504 fa505 fa506 fa507 fa508 fa509 fa510 fa511 fa512 fa513 fa514 fa515 fa516 fa517 fa518 fa519 fa520 fa521 fa388 fa389 fa390 fa391 fa392
save "wavefam10.dta"

** 2018 dataset
use "cf18k_EN_1.0p.dta", clear
rename cf18k* fa*
g wave=2018
** Changes in the variables in terms of order/names
drop fa432 fa005 fa449 fa007 fa008 fa008 fa450 fa011 fa012 fa401 fa013 fa014 fa015 fa016 fa451 fa398 fa018 fa399 fa019 fa400 fa020 fa452 fa022 fa453 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa489 fa490 fa491 fa492 fa493 fa494 fa495 fa496 fa497 fa498 fa499 fa500 fa501 fa502 fa503 fa434 fa435 fa436 fa437 fa438 fa439 fa440 fa441 fa442 fa443 fa444 fa445 fa446 fa447 fa448 fa297 fa298 fa299 fa300 fa301 fa302 fa303 fa304 fa305 fa306 fa307 fa308 fa309 fa310 fa311 fa312 fa313 fa314 fa315 fa316 fa317 fa318 fa319 fa320 fa321 fa322 fa323 fa324 fa325 fa326 fa340 fa341 fa342 fa343 fa344 fa345 fa346 fa347 fa348 fa349 fa350 fa351 fa352 fa353 fa354 fa355 fa356 fa357 fa358 fa359 fa360 fa361 fa362 fa363 fa364 fa365 fa366 fa367 fa368 fa369 fa504 fa505 fa506 fa507 fa508 fa509 fa510 fa511 fa512 fa513 fa514 fa515 fa516 fa517 fa518 fa519 fa520 fa521 fa388 fa389 fa390 fa391 fa392
save "wavefam11.dta"

** 2019 dataset
use "cf19l_EN_1.0p.dta", clear
rename cf19l* fa*
g wave=2019
** Changes in the variables in terms of order/names
drop fa432 fa005 fa449 fa007 fa008 fa008 fa450 fa011 fa012 fa401 fa013 fa014 fa015 fa016 fa451 fa398 fa018 fa399 fa019 fa400 fa020 fa452 fa022 fa453 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa489 fa490 fa491 fa492 fa493 fa494 fa495 fa496 fa497 fa498 fa499 fa500 fa501 fa502 fa503 fa434 fa435 fa436 fa437 fa438 fa439 fa440 fa441 fa442 fa443 fa444 fa445 fa446 fa447 fa448 fa297 fa298 fa299 fa300 fa301 fa302 fa303 fa304 fa305 fa306 fa307 fa308 fa309 fa310 fa311 fa312 fa313 fa314 fa315 fa316 fa317 fa318 fa319 fa320 fa321 fa322 fa323 fa324 fa325 fa326 fa340 fa341 fa342 fa343 fa344 fa345 fa346 fa347 fa348 fa349 fa350 fa351 fa352 fa353 fa354 fa355 fa356 fa357 fa358 fa359 fa360 fa361 fa362 fa363 fa364 fa365 fa366 fa367 fa368 fa369 fa504 fa505 fa506 fa507 fa508 fa509 fa510 fa511 fa512 fa513 fa514 fa515 fa516 fa517 fa518 fa519 fa520 fa521 fa388 fa389 fa390 fa391 fa392
save "wavefam12.dta"

** 2020 dataset
use "cf20m_EN_1.0p.dta", clear
rename cf20m* fa*
g wave=2020
** Changes in the variables in terms of order/names
drop fa005 fa449 fa007 fa008 fa008 fa450 fa011 fa012 fa401 fa013 fa014 fa015 fa016 fa451 fa398 fa018 fa399 fa019 fa400 fa020 fa452 fa022 fa453 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa489 fa490 fa491 fa492 fa493 fa494 fa495 fa496 fa497 fa498 fa499 fa500 fa501 fa502 fa503 fa434 fa435 fa436 fa437 fa438 fa439 fa440 fa441 fa442 fa443 fa444 fa445 fa446 fa447 fa448 fa297 fa298 fa299 fa300 fa301 fa302 fa303 fa304 fa305 fa306 fa307 fa308 fa309 fa310 fa311 fa312 fa313 fa314 fa315 fa316 fa317 fa318 fa319 fa320 fa321 fa323 fa324 fa325 fa326 fa340 fa341 fa342 fa343 fa344 fa345 fa346 fa347 fa348 fa349 fa350 fa351 fa352 fa353 fa354 fa355 fa356 fa357 fa358 fa359 fa360 fa361 fa362 fa363 fa364 fa365 fa366 fa367 fa368 fa369 fa504 fa505 fa506 fa507 fa508 fa509 fa510 fa511 fa512 fa513 fa514 fa515 fa516 fa517 fa518 fa519 fa520 fa521 fa388 fa389 fa390 fa391 fa392
save "wavefam13.dta"

** 2021 dataset
use "cf21n_EN_1.0p.dta", clear
rename cf21n* fa*
g wave=2021
** Changes in the variables in terms of order/names
drop fa005 fa449 fa007 fa008 fa008 fa450 fa011 fa012 fa401 fa013 fa014 fa015 fa016 fa451 fa398 fa018 fa399 fa019 fa400 fa020 fa452 fa022 fa453 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa489 fa490 fa491 fa492 fa493 fa494 fa495 fa496 fa497 fa498 fa499 fa500 fa501 fa502 fa503 fa434 fa435 fa436 fa437 fa438 fa439 fa440 fa441 fa442 fa443 fa444 fa445 fa446 fa447 fa448 fa297 fa298 fa299 fa300 fa301 fa302 fa303 fa304 fa305 fa306 fa307 fa308 fa309 fa310 fa311 fa312 fa313 fa314 fa315 fa316 fa317 fa318 fa319 fa320 fa321 fa323 fa324 fa325 fa326 fa340 fa341 fa342 fa343 fa344 fa345 fa346 fa347 fa348 fa349 fa350 fa351 fa352 fa353 fa354 fa355 fa356 fa357 fa358 fa359 fa360 fa361 fa362 fa363 fa364 fa365 fa366 fa367 fa368 fa369 fa504 fa505 fa506 fa507 fa508 fa509 fa510 fa511 fa512 fa513 fa514 fa515 fa516 fa517 fa518 fa519 fa520 fa521 fa388 fa389 fa390 fa391 fa392
save "wavefam14.dta"

** 2022 dataset
use "cf22o_EN_1.0p.dta", clear
rename cf22o* fa*
g wave=2022
** Changes in the variables in terms of order/names
drop fa005 fa449 fa007 fa008 fa008 fa450 fa011 fa012 fa401 fa013 fa014 fa015 fa016 fa451 fa398 fa018 fa399 fa019 fa400 fa020 fa452 fa022 fa453 fa098 fa099 fa100 fa101 fa102 fa103 fa104 fa105 fa106 fa107 fa108 fa109 fa110 fa111 fa112 fa113 fa114 fa115 fa116 fa117 fa118 fa119 fa120 fa121 fa122 fa123 fa124 fa125 fa126 fa127 fa143 fa144 fa145 fa146 fa147 fa148 fa149 fa150 fa151 fa152 fa153 fa154 fa155 fa156 fa157 fa158 fa159 fa160 fa161 fa162 fa163 fa164 fa165 fa166 fa180 fa181 fa182 fa183 fa184 fa185 fa186 fa218 fa219 fa220 fa221 fa222 fa223 fa224 fa489 fa490 fa491 fa492 fa493 fa494 fa495 fa496 fa497 fa498 fa499 fa500 fa501 fa502 fa503 fa434 fa435 fa436 fa437 fa438 fa439 fa440 fa441 fa442 fa443 fa444 fa445 fa446 fa447 fa448 fa297 fa298 fa299 fa300 fa301 fa302 fa303 fa304 fa305 fa306 fa307 fa308 fa309 fa310 fa311 fa312 fa313 fa314 fa315 fa316 fa317 fa318 fa319 fa320 fa321 fa323 fa324 fa325 fa326 fa340 fa341 fa342 fa343 fa344 fa345 fa346 fa347 fa348 fa349 fa350 fa351 fa352 fa353 fa354 fa355 fa356 fa357 fa358 fa359 fa360 fa361 fa362 fa363 fa364 fa365 fa366 fa367 fa368 fa369 fa504 fa505 fa506 fa507 fa508 fa509 fa510 fa511 fa512 fa513 fa514 fa515 fa516 fa517 fa518 fa519 fa520 fa521 fa388 fa389 fa390 fa391 fa392
save "wavefam15.dta"


********************************************************************************

** Merger of the family datasets
use "wavefam1.dta", clear
append using "wavefam2.dta"
append using "wavefam3.dta"
append using "wavefam4.dta"
append using "wavefam5.dta"
append using "wavefam6.dta", force
append using "wavefam7.dta", force
append using "wavefam8.dta", force
append using "wavefam9.dta"
append using "wavefam10.dta"
append using "wavefam11.dta"
append using "wavefam12.dta"
append using "wavefam13.dta"
append using "wavefam14.dta"
append using "wavefam15.dta"

/* Save the new dataset */save "family1-15.dta"


********************************************************************************

**# 3. Clean and prepare the datasets with questions regarding educational attainment and occupational status.

** 2008 dataset
/* Open dataset */ use "cw08a_EN_1.1p.dta", clear
/* Drop prefixes in variable names to facilitate dataset combination*/ rename cw08a* w*
ta w_m
/* Generate wave identificator*/ g wave=2008
/* Save new dataset*/ save "wavework1.dta"

** 2009 dataset
use "cw09b_EN_3.0p.dta", clear
rename cw09b* w*
ta w_m
g wave=2009
save "wavework2.dta"

** 2010 dataset
use "cw10c_EN_1.0p.dta", clear
rename cw10c* w*
ta w_m
g wave=2010
save "wavework3.dta"

** 2011 dataset
use "cw11d_EN_1.0p.dta", clear
rename cw11d* w*
ta w_m
g wave=2011
save "wavework4.dta"

** 2012 dataset
use "cw12e_EN_1.0p.dta", clear
rename cw12e* w*
ta w_m
g wave=2012
save "wavework5.dta"

** 2013 dataset
use "cw13f_EN_1.0p.dta", clear
rename cw13f* w*
ta w_m
g wave=2013
/* Variables that need some work to facilitate merger*/
ta w502
ta w504
tostring w504 w504, replace format(%11.0f)
save "wavework6.dta"

** 2014 dataset 
use "cw14g_EN_1.0p.dta", clear
rename cw14g* w*
ta w_m
g wave=2014
save "wavework7.dta"

** 2015 dataset 
use "cw15h_EN_2.0p.dta", clear
rename cw15h* w*
ta w_m
g wave=2015
save "wavework8.dta"

** 2016 dataset
use "cw16i_EN_2.0p.dta", clear
rename cw16i* w*
ta w_m
g wave=2016
save "wavework9.dta"

** 2017 dataset
use "cw17j_EN_2.0p.dta", clear
rename cw17j* w*
ta w_m
g wave=2017
save "wavework10.dta"

** 2018 dataset
use "cw18k_EN_2.0p.dta", clear
rename cw18k* w*
ta w_m
g wave=2018
save "wavework11.dta", replace

** 2019 dataset
use "cw19l_EN_3.0p.dta", clear
rename cw19l* w*
ta w_m
g wave=2019
save "wavework12.dta"

** 2020 dataset 
use "cw20m_EN_1.0p.dta", clear
rename cw20m* w*
ta w_m
g wave=2020
save "wavework13.dta"

** 2021 dataset
use "cw21n_EN_1.0p.dta", clear
rename cw21n* w*
ta w_m
g wave=2021
save "wavework14.dta" 

** 2022 dataset
use "cw22o_EN_1.0p.dta", clear
rename cw22o* w*
ta w_m
g wave=2022
save "wavework15.dta"


*********************************************************************************

** Create merger

use "wavework1.dta", clear
append using "wavework2.dta"
append using "wavework3.dta"
append using "wavework4.dta"
append using "wavework5.dta"
append using "wavework6.dta", force
append using "wavework7.dta", force
append using "wavework8.dta"
append using "wavework9.dta"
append using "wavework10.dta"
append using "wavework11.dta"
append using "wavework12.dta"
append using "wavework13.dta"
append using "wavework14.dta"
append using "wavework15.dta"

save "work1-15.dta"

********************************************************************************
********************************************************************************

**# 4. Merger

use "family1-15.dta", clear
merge m:m nomem_encr wave using "politics1-15", update
drop if _merge<3
save "familyandpolitics.dta", replace
rename _merge mergepol
merge m:m nomem_encr wave using "work1-15.dta", update
drop if _merge<3
save "pooled1-15.dta", replace

**********************************************************************************